# 通过datetime模块完成时间戳, datetime.datetime对象, 格式化字符串三者之间的转换

import time
import datetime

# 获取当前时间
now = datetime.datetime.today()
print(now)

# datetime >>> str
time_str = now.strftime("%Y-%m-%d %H:%M:%S")
print(time_str)
print(type(time_str))

# str >>> datetime
time_datetime = datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S")
print(time_datetime)
print(type(time_datetime))

# datetime >>> timestamp
now_timestamp = now.timestamp()
print(now_timestamp)

# timestamp >>> datetime
now_datetime = datetime.datetime.fromtimestamp(now_timestamp, tz=None)
print(now_datetime)

# 封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02.
from datetime import timedelta
def get_date(day_delta):
    if int(day_delta) != 0:
        print(now+timedelta(days=int(day_delta)))
    else:
        print("输入错误")
day_delta = input("请输入需要调整的天数:")
get_date(day_delta)




